package com.ms.demo;

import com.ms.demo.entity.Emp;
import com.ms.demo.mapper.EmpDataMapper;
import com.ms.demo.utils.SqlSessionUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 批量操作MySQL
 * @author: ms
 * @create: 2022-08-20 17:23
 */
public class MybatisMysqlTest2 {

    @Test
    public void batchInsertEmpTest(){
        SqlSession session = SqlSessionUtils.getSqlSession();
        EmpDataMapper mapper = session.getMapper(EmpDataMapper.class);
        List<Emp> dataList = new ArrayList<Emp>();
        dataList.add(new Emp(null,"李四1",23,"男","在职","2", null));
        dataList.add(new Emp(null,"李四2",23,"男","在职","2", null));
        dataList.add(new Emp(null,"李四3",23,"男","在职","2", null));
        mapper.batchAddNewEmp(dataList);
    }

    @Test
    public void batchDeleteEmpTest(){
        SqlSession session = SqlSessionUtils.getSqlSession();
        EmpDataMapper mapper = session.getMapper(EmpDataMapper.class);
        Integer[] ids = {10,11};
        mapper.batchDeleteEmpById(ids);
    }

    @Test
    public void batchUpdateEmpTest(){//有bug
        SqlSession session = SqlSessionUtils.getSqlSession();
        EmpDataMapper mapper = session.getMapper(EmpDataMapper.class);
        List<Emp> dataList = new ArrayList<Emp>();
        dataList.add(new Emp(7,"李四3",24,"男","在职","2", null));
        dataList.add(new Emp(9,"李四4",25,"nv","在职","2", null));
        mapper.batchUpdateEmp(dataList);
    }
}